<template>
  <div class="app-container">
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px" :label-position="labelPosition">
      <el-form-item label="日期" prop="ssrqid">
        <el-input
          v-model="queryParams.ssrqid"
          :disabled="true"
        />
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="historyAssignmentDetailDetailList"
    >
      <af-table-column prop="dzopmc" label="单类" width="90" fixed="left"></af-table-column>
      <af-table-column prop="pzbh" label="单号"></af-table-column>
      <af-table-column prop="sptm" label="客户条码"></af-table-column>
      <af-table-column prop="sptmc" label="仓库条码"></af-table-column>
      <af-table-column prop="prrq" label="创建时间"></af-table-column>
      <af-table-column prop="rsopmc" label="创建人"></af-table-column>
      <af-table-column prop="spckmc" label="仓库"></af-table-column>
      <af-table-column prop="ckcw" label="仓位"></af-table-column>
      <af-table-column prop="spjs" label="件数"></af-table-column>
      <af-table-column prop="spjsl" label="单重(KG)"></af-table-column>
      <af-table-column prop="spsl" label="重量(吨)"></af-table-column>
      <af-table-column prop="shzt" label="审核状态"></af-table-column>
      <af-table-column prop="spzs" label="物品规格"></af-table-column>
      <af-table-column prop="spcd" label="品牌"></af-table-column>
      <af-table-column prop="spgh" label="柜号"></af-table-column>
      <af-table-column prop="spbh" label="批号"></af-table-column>
      <af-table-column prop="khmc" label="所有者"></af-table-column>
      <af-table-column prop="itbz" label="备注"></af-table-column>
      <af-table-column prop="ssrqid" label="出/入仓日期"></af-table-column>
      <af-table-column prop="wpggA" label="纱支"></af-table-column>
      <af-table-column prop="wpggB" label="工艺"></af-table-column>
      <af-table-column prop="wpggC" label="工序"></af-table-column>
      <af-table-column prop="wpggD" label="用途"></af-table-column>
      <af-table-column prop="wpggE" label="产地"></af-table-column>
      <af-table-column prop="wpggF" label="漂染性"></af-table-column>
      <af-table-column prop="wpggG" label="生产日期"></af-table-column>
      <af-table-column prop="wpggH" label="颜色"></af-table-column>
    </el-table>
     <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
  </div>
</template>

<script>
import { getHistoryAssignmentDetail } from "@/api/storage/dataAnalysis/historyAssignment";

export default {
  name: "HistoryAssignmentDetail",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //对齐
      labelPosition: "right",
      //加载列表
      loading:true,
      // 查询参数
      queryParams: {
        ally: "",
        khid: "",
        khlx: "",
        khmcid: "",
        rqid: "",
        spckid: "",
        spkhmcid: "",
        ssrqid: "",
        ssrqid1: "",
        ssrqid2: "",
        zt: ""
      },
      // 历史作业量详情列表
      historyAssignmentDetailDetailList: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const query = to.query
    next(vm => {   
      if(Object.keys(query).length > 0) {
        vm.queryParams.ssrqid = query.ssrqid
        vm.queryParams.spckid = query.spckid
        vm.getList()
      }
    })
  },
  methods: {
    /** 查询历史作业量详情列表 */
    getList() {
      this.loading = true
      getHistoryAssignmentDetail(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.historyAssignmentDetailDetailList = response.rows;
        this.total = response.total;
        this.loading = false
      });
    },

    //合计
    getSummaries({ columns, data }) {
      const sums = []
      columns.forEach((column, index) => {
        if(index === 0) {
          sums[index] = "合计"
			    return
        }
        if ((column.property === "spjs" || column.property === "spsl")) {
          const values = data.map((item) => {
            return parseFloat(this.delcommafy(item[column.property]))
          });
          sums[index] = values.reduce((prev, curr) => {
            return prev + curr
          }, 0);
        }
      })
      return sums
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
